/**
 * @param {number[]} nums
 * @return {number}
 */
var removeDuplicates = function (nums) {
  let count = 2
  for (let i = 1; i < nums.length; i++) {
    if (nums[i] == nums[i - 1]) {

      if (count == 0) {
        nums.splice(i, 1)
      } else
        count--
    } else {
      count = 2
    }
  }

  return nums.length
};

removeDuplicates([1, 1, 1, 2, 2, 3])